package likou;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/07/08 11:09
 */
public class _930 {
    public int numSubarraysWithSum(int[] nums, int goal) {
        Map<Integer,Integer> map = new HashMap<>();
        int res = 0;
        int sum = 0;
        map.put(0,0);
        for (int num : nums) {
            sum += num;
            res += map.getOrDefault(goal - sum, 0);
            map.merge(sum, 1, Integer::sum);
        }
        return res;
    }
}
